<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-select v-model="queryParams.status" placeholder="请选择出租状态" clearable>
          <el-option label="待租中" value="0"></el-option>
          <el-option label="已出租" value="1"></el-option>
          <el-option label="维修中" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="queryParams.publishStatus" placeholder="请选择发布状态" clearable>
          <el-option label="未发布" value="0"></el-option>
          <el-option label="已发布" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryParams.name" placeholder="请输入楼盘关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="queryParams.roomName" placeholder="请输入房源名称关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleUpdate1(1)"
        >推荐房源</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate2(2)"
        >取消推荐</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="房源图片" align="center" >
        <template slot-scope="scope">
        <el-image
          style="width: 100px; height: 100px"
          :src="scope.row.frontCover"
          fit="fit"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="房源名称" align="center" prop="roomName" />
      <el-table-column label="楼盘名称" align="center" prop="name" />
      <el-table-column label="房源编号" align="center" prop="roomCode" />
      <el-table-column label="面积" align="center" prop="proportion" />
      <el-table-column label="租金" align="center" prop="rental" />
      <el-table-column label="出租状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">待租</span>
          <span v-else-if="scope.row.status==1">已出租</span>
          <span v-else>装修</span>
        </template>
      </el-table-column>
      <el-table-column label="发布人" align="center" prop="username" />
      <el-table-column label="发布状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.publishStatus==0">未发布</span>
          <span v-else>已发布</span>
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.recommended==1">推荐</span>
          <span v-else>不推荐</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, editRecommended } from "@/api/system/info";

export default {
  name: "Info",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseId: null,
        frontCover: null,
        publishStatus:null,
        roomName: null,
        roomCode: null,
        proportion: null,
        direction: null,
        rental: null,
        decorateStyle: null,
        buildingName: null,
        floor: null,
        floorCount: null,
        status: null,
        privateFacility: null,
        recommended: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        deptId: null,
        styleId: null,
        finishDate: null,
        vacancyDate: null,
        delFlg: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        delFlg: [
          { required: true, message: "删除标识。0:未删除，1：删除不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        console.log(response.rows);
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        houseId: null,
        frontCover: null,
        roomName: null,
        roomCode: null,
        proportion: null,
        direction: null,
        rental: null,
        decorateStyle: null,
        buildingName: null,
        floor: null,
        floorCount: null,
        status: 0,
        privateFacility: null,
        recommended: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        deptId: null,
        createTime: null,
        styleId: null,
        finishDate: null,
        vacancyDate: null,
        delFlg: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleUpdate1(recommended){
      this.form.recommended=recommended;
      if(this.ids==null){
        this.$message.error("请选择数据");
        return;
      }
      if(confirm("确定要推荐选中的房源？")){
        this.editRecommended();
      }
    },
    handleUpdate2(recommended){
      this.form.recommended=recommended;
      if(this.ids==null){
        this.$message.error("请选择数据");
        return;
      }
      if(confirm("确定要取消选中的房源？")){
        this.editRecommended();
      }
    },
    /** 修改按钮操作 */
    editRecommended() {
      this.form.ids=this.ids;
      editRecommended(this.form).then(response => {
        console.log(response);
        if(response.code==200){
            this.$message.success("操作成功");
            this.getList();
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
